var gulp = require('gulp'),
	moment = require('moment'),
	concat = require('gulp-concat'),
	connect = require('gulp-connect'),
	uglify = require('gulp-uglify'),//js压缩
	cssmin = require('gulp-clean-css'),//css压缩
	ngAnnotate = require('gulp-ng-annotate'),
	templateCache = require('gulp-angular-templatecache'),
	fs = require('fs'),
	path = require('path');

var listFiles = function(path,fileList) {
    if( fs.existsSync(path) ) {
        var files = fs.readdirSync(path);
        files.forEach(function(file,index){
			if(file!='.svn'){
				var curPath = path + "/" + file;
				if(fs.statSync(curPath).isDirectory()) { // recurse
					listFiles(curPath,fileList);
				} else {
					fileList.push(curPath);
				}
			}
        });
    }
};

gulp.task('build', function(){
	var file = 'css/flat.css';
	fs.unlinkSync('css/flat.min.css');
	return gulp.src(file)
		.pipe(cssmin())
		.pipe(gulp.dest('css/flat.min.css'));
/**
	var fileList = [];
	fileList.forEach(function(file,idx){
		var _path = file.substring(0,file.lastIndexOf('/'));
		_path = _path.replace(srcPath,distPath);
		var lastIdx=file.lastIndexOf(".");  
		var suffix=file.substring(lastIdx,file.length);//后缀名
		if(suffix === 'js'){
			return gulp.src(file)
				.pipe(ngAnnotate())
				.pipe(uglify())
				.pipe(gulp.dest(_path));
		}else if(suffix === 'css'){
			return gulp.src(file)
				.pipe(cssmin())
				.pipe(gulp.dest(_path));
		}else if(suffix === 'html'){
			//使用templateCache压缩，此处不拷贝
			return gulp.src(file)
				.pipe(gulp.dest(_path));
		}else{
			return gulp.src(file)
				.pipe(gulp.dest(_path));
		}
	});
**/
});

gulp.task('default', ['build']);